package Phase;

import StateInformation.GameState;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class FileGameStateSaver implements GameStateSaver {

    @Override
    public boolean save(GameState gameState, String user) {
        try {
            String direccion = "C:/Users/Jonatan/Desktop/pruebaArkanoid.txt";
            File file = new File(direccion);
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
            objectOutputStream.writeObject(gameState);
            objectOutputStream.flush();
            objectOutputStream.close();
            return true;
        } catch (Exception e) {
            System.out.println("Problemas en el guardado. " + e.toString());
        }
        return false;
    }

    @Override
    public GameState load(String user) {
        try {
            String direccion = "C:/Users/Jonatan/Desktop/pruebaArkanoid.txt";
            File file = new File(direccion);
            FileInputStream fileInputStream = new FileInputStream(file);
            ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
            GameState gameState = (GameState) objectInputStream.readObject();
            objectInputStream.close();
            return gameState;
        } catch (Exception e) {
            System.out.println("Problemas en la carga. " + e.toString());
        }
        return null;
    }
}
